package com.markedquilt.SwordForOffer;

import com.markedquilt.SwordForOffer.entity.TreeNode;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.Queue;

/**
 * Title:
 * Project: LeetcodeProblem
 *
 * @author ZhangKe
 * Created on 2020/11/30
 */
public class _levelOrder32_2 {

    public List<List<Integer>> levelOrder(TreeNode root) {
        Queue<TreeNode> queue = new LinkedList<>();
        List<List<Integer>> array = new LinkedList<>();
        int level=0,printed=1;
        if (root==null){
            return null;
        }else{
            queue.add(root);
            LinkedList<Integer> rootVal = new LinkedList<>();
            rootVal.add(root.val);
            while(!queue.isEmpty()){
                TreeNode node = queue.poll();
                List<Integer> newLevel = new LinkedList<>();
                if (node.left!=null || node.right!=null){
                    if (node.left!=null){
                        queue.add(node.left);
                        newLevel.add(node.left.val);
                    }
                    if (node.right!=null){
                        queue.add(node.right);
                        printed++;
                        newLevel.add(node.right.val);
                    }
                }
            }
            return result;
        }
    }
    public static void main(String[] args) {
        TreeNode three = new TreeNode(3);
        TreeNode two = new TreeNode(2);
        TreeNode five = new TreeNode(5);
        TreeNode zero = new TreeNode(0);
        TreeNode one = new TreeNode(1);
        two.left = zero;
        two.right = one;
        three.left = two;
        three.right = five;
    }
}
